<script>
import closeIcon from "../assets/close.png"
import dateUtils from "@/utils/dateUtils"

export default {
  name: "practiceReport",
  computed: {
    dateUtils() {
      return dateUtils
    },
  },
  data() {
    return {
      userDoTopicScore: {
        errorTopicNum: 0, // 错题数
        isCalculateScore: 0, // 是否计算分数
        noDoNum: 0, // 未做题数
        rightTopicNum: 0, // 正确题数
        score: 0, // 得分
        totalTopicNum: 0, // 总题数
        useTime: 0, // 用时
      },
      closeIcon,
      promise: {
        resolve: null,
      },
    }
  },
  methods: {
    open(userDoTopicScore) {
      return new Promise((resolve, reject) => {
        this.promise.resolve = resolve
        this.userDoTopicScore = userDoTopicScore
        this.$refs.popup.open()
      })
    },
  },
}
</script>

<template>
  <uni-popup
    ref="popup"
    type="bottom"
    @change="
      (e) => {
        if (e.show === false) {
          promise.resolve()
        }
      }
    "
  >
    <view class="component">
      <view class="header">
        <view class="placeholder"></view>
        <view class="title">本次做题报告</view>
        <image class="close-btn" :src="closeIcon"></image>
      </view>
      <view class="content">
        <view class="item">
          <view class="label">总得分：</view>
          <view class="value">{{ userDoTopicScore.score }}</view>
        </view>
        <view class="item">
          <view class="label">总题数：</view>
          <view class="value">{{ userDoTopicScore.totalTopicNum }}</view>
        </view>
        <view class="item">
          <view class="label">答对题数：</view>
          <view class="value">
            <text style="color: var(--success-color)">{{ userDoTopicScore.rightTopicNum }}</text>
          </view>
        </view>
        <view class="item">
          <view class="label">答错题数：</view>
          <view class="value">
            <text style="color: var(--error-color)">{{ userDoTopicScore.errorTopicNum }}</text>
          </view>
        </view>
        <view class="item">
          <view class="label">未答题数：</view>
          <view class="value">
            <text style="color: var(--warning-color)">{{ userDoTopicScore.noDoNum }}</text>
          </view>
        </view>
        <view class="item">
          <view class="label">用时：</view>
          <view class="value">{{ dateUtils.formatTimeChinese(userDoTopicScore.useTime) }}</view>
        </view>
      </view>
      <view class="confirm-btn" @click="$refs.popup.close()">查看答案解析</view>
    </view>
  </uni-popup>
</template>

<style scoped lang="scss">
.component {
  background: white;
  border-top-left-radius: 40rpx;
  border-top-right-radius: 40rpx;
  padding: 40rpx;
  > .header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    > .placeholder {
      width: 60rpx;
    }
    > .title {
      font-size: 34rpx;
    }
    > .close-btn {
      width: 60rpx;
      height: 60rpx;
    }
  }
  > .content {
    margin-top: 40rpx;
    > .item {
      font-size: 30rpx;
      display: flex;
      &:not(:last-child) {
        margin-bottom: 30rpx;
      }
      > .label {
        color: var(--text-color-light);
      }
    }
  }
  > .confirm-btn {
    margin-top: 40rpx;
    padding: 20rpx 0;
    width: 100%;
    background: var(--theme-color);
    color: white;
    font-size: 30rpx;
    box-sizing: border-box;
    text-align: center;
    border-radius: 40rpx;
  }
}
</style>
